package com.woniu.order.service.impl;

import com.woniu.commons.feign.FeignGoodsService;
import com.woniu.order.mapper.OrderMapper;
import com.woniu.order.service.OrderService;
import com.woniu.order.vo.OrderVo;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class OrderServiceImpl implements OrderService {
    @Resource
    private OrderMapper orderMapper;
    @Resource
    private FeignGoodsService feignGoodsService;

    //分布式事务
    //@Transactional//开启事务
    @GlobalTransactional//开启全局事务
    @Override
    public boolean add(OrderVo vo, int uid) {
        //删减库存
        feignGoodsService.updateStock(vo.getGid(), vo.getNum());
        //下订单
        orderMapper.add(uid);

        return false;
    }
}
